﻿using System;
using System.Collections.Generic;
using System.Linq;
/*
 This file was create by Xusion at 01.06.2011
 */
using System.Web;
using System.Web.SessionState;

using WeiBo.SinaAPI;

namespace TCS.Web.MembersHome
{
    /// <summary>
    /// Summary description for SinaApiCallBack
    /// </summary>
    public class SinaApiCallBack : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");

            //?oauth_token=c1be009a14741c7993f3dd390efdecb7&oauth_verifier=727708
            string oauth_token = context.Request["oauth_token"];
            string oauth_verifier = context.Request["oauth_verifier"];

            if (!string.IsNullOrEmpty(oauth_token) && !string.IsNullOrEmpty(oauth_verifier) && SinaBase.oAuth != null)
            {
                oAuthSina oauth = SinaBase.oAuth;
                oauth.Verifier = oauth_verifier;
                oauth.Token = oauth_token;
                oauth.AccessTokenGet(oauth_token);

                SinaApiWebService sina = new SinaApiWebService();
                SinaBase.User = UserController.GetModelByUserXml(sina.users_show(oauth, "xml", "user_id=" + oauth.AccessUesrID));
            }
            context.Response.Redirect("/membershome/BindWB.aspx?u="+context.Request.Params["u"]);

        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}